package edu.albany.csi518.test;

import edu.albany.csi518.util.CustomFileReader;
import edu.albany.csi518.util.CustomFileWriter;
import java.io.File;

/**
 *
 * @author John M. Lien
 */
public class Sample_IO {
    
    public static void createOutputFile(){
        CustomFileWriter write = new CustomFileWriter("sample_output");
        
        //Test basic printing to file.
        write.println("Test 1");
        write.println(101010101);
        write.println(true);
        write.println('A');
        write.print("Test ");
        write.print("2");
        write.println();
        write.closeFile();
        
        //Test file appending.
        write.appendFile("sample_output");
        write.println("Test 3");
        write.closeFile();
        
        //Test file copying.
        write.copy_file("sample_output", "sample_output_2");
    }
    
    public static void readInputFile(){
        CustomFileReader read = new CustomFileReader("sample_output");
        
        //Iterate through each line.
        System.out.println("##### Test 1 #####");
        while(read.hasNextLine()){
            System.out.println(read.getNextLine());
        }
        
        //Iterate through each line without using constructor.
        System.out.println("##### Test 2 #####");
        read.openFile("sample_output_2");
        while(read.hasNextLine()){
            System.out.println(read.getNextLine());
            System.out.println(read.getCurrentLine());
            System.out.println();
        }
        read.closeFile();
        
        //Test other fuctions.
        System.out.println("##### Test 3 #####");
        read.reOpenLastUsedFile();
        read.closeFile();
        read.printContentsToStandardOutput("sample_output");
        
        //Remove created test files from local project directory
        new File("sample_output").delete();
        new File("sample_output_2").delete();
    }
    
    public static void main(String...args){
        createOutputFile();
        readInputFile();
    }
}
